﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace LinqProviders.LinqToNaver
{
    /// <summary>
    /// 추천검색어
    /// </summary>
    public class RecmdSearchResult : NaverSearchResult
    {
        /// <summary>
        /// Gets or sets the keyword. 검색 키워드.
        /// </summary>
        /// <value>The keyword.</value>
        public string Keyword { get; set; }

        /// <summary>
        /// Gets the channel query.
        /// </summary>
        /// <param name="xdoc">The xdoc.</param>
        /// <returns></returns>
        public static IEnumerable<RecmdSearchResult> Parse(XDocument xdoc)
        {
            var result = xdoc.Descendants("result").FirstOrDefault();

            return from items in result.Descendants("item")
                   select new RecmdSearchResult
                   {
                       Keyword = items.Value
                   };
        }

        protected override object Parse(string input, string requestedQuery, out int count, out int totalCount)
        {
            IEnumerable<RecmdSearchResult> resultList = new List<RecmdSearchResult>();
            count = 0;

            if (String.IsNullOrEmpty(input) == false)
            {
                XDocument document = XDocument.Parse(input);
                resultList = RecmdSearchResult.Parse(document);
            }
            totalCount = resultList.Count();
            return resultList;
        }
    }

    
}
